package com.hm.recycle.auto;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;

import com.hm.recycle.share.service.DbDocumentDeleteRecycleService;
import com.hm.recycle.share.service.DbDocumentNewRecycleService;
import com.hm.recycle.share.service.DbDocumentUpdateRecycleService;

/**
 * @author shishun.wang
 * @date 下午4:58:02 2016年6月16日
 * @version 1.0
 * @describe
 */
@SuppressWarnings("unused")
@Configuration
@EnableConfigurationProperties({ RecycleProperties.class })
public class RecycleAutoConfiguration {

	@Autowired
	private RecycleProperties recycleProperties;
	
	@Autowired
	private BeanFactory beanFactory;

	@Bean(name = DbDocumentDeleteRecycleService.HTTP_INVOKER_EXPORT_CONTEXT)
	public HttpInvokerServiceExporter dbDocumentDeleteRecycleService() {
		HttpInvokerServiceExporter httpInvokerServiceExporter = new HttpInvokerServiceExporter();
		httpInvokerServiceExporter.setServiceInterface(DbDocumentDeleteRecycleService.class);
		httpInvokerServiceExporter.setService(beanFactory.getBean(DbDocumentDeleteRecycleService.class));
		httpInvokerServiceExporter.afterPropertiesSet();
		return httpInvokerServiceExporter;
	}

	@Bean(name = DbDocumentUpdateRecycleService.HTTP_INVOKER_EXPORT_CONTEXT)
	public HttpInvokerServiceExporter dbDocumentUpdateRecycleService() {
		HttpInvokerServiceExporter httpInvokerServiceExporter = new HttpInvokerServiceExporter();
		httpInvokerServiceExporter.setServiceInterface(DbDocumentUpdateRecycleService.class);
		httpInvokerServiceExporter.setService(beanFactory.getBean(DbDocumentUpdateRecycleService.class));
		httpInvokerServiceExporter.afterPropertiesSet();
		return httpInvokerServiceExporter;
	}

	@Bean(name = DbDocumentNewRecycleService.HTTP_INVOKER_EXPORT_CONTEXT)
	public HttpInvokerServiceExporter dbDocumentNewRecycleService() {
		HttpInvokerServiceExporter httpInvokerServiceExporter = new HttpInvokerServiceExporter();
		httpInvokerServiceExporter.setServiceInterface(DbDocumentNewRecycleService.class);
		httpInvokerServiceExporter.setService(beanFactory.getBean(DbDocumentNewRecycleService.class));
		httpInvokerServiceExporter.afterPropertiesSet();
		return httpInvokerServiceExporter;
	}
}
